<template>
  <div class="headerBox">
    <div @click="setPageType('myTodo')">
      <van-icon v-if="pageType === 'new'" name="arrow-left" />
    </div>
    <p>{{ title }}</p>
    <div @click="setPageType('new')">
      <van-icon v-if="pageType === 'myTodo'" name="plus" />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, watch } from "vue";

export default defineComponent({
  name: "KyHeader",
  props: {
    pageType: {
      type: String,
      default: "myTodo"
    }
  },
  setup(props, context) {
    const state = reactive({
      title: "我的待办"
    });

    watch(
      () => props.pageType,
      () => {
        state.title = props.pageType === "new" ? "新增任务" : "我的待办";
      }
    );

    function setPageType(val: string) {
      context.emit("get-page-type", val);
    }

    return {
      ...toRefs(state),
      setPageType
    };
  }
});
</script>

<style lang="scss" scoped>
.headerBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 18px;
  font-size: 16px;
  font-weight: bold;
  height: 40px;
  border-bottom: 1px solid black;
  background: white;
}
</style>
